#ifndef __QUICK_IM_GUI_H__
#define __QUICK_IM_GUI_H__

#include "imgui.h"
// #include "imgui_impl_glfw.h"
// #include "imgui_impl_opengl3.h"
#include <stdio.h>
#define GL_SILENCE_DEPRECATION
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <GLES2/gl2.h>
#endif
#undef GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h> // Will drag system OpenGL headers

#include <functional>
#include <string>

#define LOG(...) { ::printf("%s(%d):", __FUNCTION__, __LINE__); ::printf(__VA_ARGS__); ::printf("\n"); }

// [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers.
// To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma.
// Your own project should not be affected, as you are likely to link with a newer binary of GLFW that is adequate for your version of Visual Studio.
#if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)
#pragma comment(lib, "legacy_stdio_definitions")
#endif

// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
#ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#endif


class QuickImGui {
public:
    explicit QuickImGui(uint32_t width, uint32_t height, const char* title, bool continuouslyRender = false);
    virtual ~QuickImGui();

    static void glfw_error_callback(int error, const char* description);

    void initialize();
    void setFrameRenderContent(const std::function<void()>& func);
    void setClearColor(ImColor color);
    void quit();
    void finalize();
    void mainLoop();

private:
    // Create GLFWwindow
    void createWindow();

    // Start the Dear ImGui frame
    void startNewFrame();

    // Render frame content
    void renderFrameContent();

    // When use high DPI screen, update scale fator for frame
    void updateFrameScale();

private:
    GLFWwindow* mWindow = nullptr;
    ImColor mClearColor;
    std::function<void()> mFrameRenderContent;
    std::string mTitle;
    uint32_t mWindowWidth;
    uint32_t mWindowHeight;
    bool mbContinuouslyRender;
};


#endif